//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.le.buddha.util;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.Character.UnicodeBlock;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串工具
 */
public class StringUtil {
    public StringUtil() {
    }

    /**
     * 验证null and 空串
     * @param str
     * @return
     */
    public static boolean isEmpty(String str) {
        return str == null || "".equals(str) || " ".equals(str);
    }

    /**
     * 查找字符对应字符串的索引
     * @param str
     * @param searchChars
     * @return
     */
    public static int indexOfAny(String str, String searchChars) {
        if (str != null && str.length() != 0 && searchChars != null && searchChars.length() != 0) {
            for(int i = 0; i < str.length(); ++i) {
                char ch = str.charAt(i);

                for(int j = 0; j < searchChars.length(); ++j) {
                    if (searchChars.charAt(j) == ch) {
                        return i;
                    }
                }
            }

            return -1;
        } else {
            return -1;
        }
    }

    public static String convert2Unicode(String str) {
        str = str == null ? "" : str;
        StringBuffer sb = new StringBuffer(1000);
        sb.setLength(0);

        for(int i = 0; i < str.length(); ++i) {
            char c = str.charAt(i);
            sb.append("\\u");
            int j = c >>> 8;
            String tmp = Integer.toHexString(j);
            if (tmp.length() == 1) {
                sb.append("0");
            }

            sb.append(tmp.toUpperCase());
            j = c & 255;
            tmp = Integer.toHexString(j);
            if (tmp.length() == 1) {
                sb.append("0");
            }

            sb.append(tmp.toUpperCase());
        }

        return new String(sb);
    }

    /**
     * 验证 非null and 非空串
     * @param str
     * @return
     */
    public static final boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    /**
     * 数组中间 拼字符串
     * @param objArr
     * @param str
     * @return
     */
    public static final String join(Object[] objArr, String str) {
        StringBuffer ret = new StringBuffer();
        if (objArr != null) {
            int len = objArr.length;

            for(int i = 0; i < len; ++i) {
                Object o = objArr[i];
                ret.append(o);
                if (i + 1 < len) {
                    ret.append(str);
                }
            }
        }

        return ret.toString();
    }

    /**
     * list中间拼字符串
     * @param objList
     * @param str
     * @return
     */
    public static final String join(List<?> objList, String str) {
        StringBuffer ret = new StringBuffer();
        if (objList != null) {
            int len = objList.size();

            for(int i = 0; i < len; ++i) {
                Object o = objList.get(i);
                ret.append(o);
                if (i + 1 < len) {
                    ret.append(str);
                }
            }
        }

        return ret.toString();
    }

    public static final ArrayList<Integer> toList(String string, String s) {
        ArrayList<Integer> list = null;
        if (isEmpty(string)) {
            return list;
        } else {
            list = new ArrayList();
            String[] arr = string.split(s);
            String[] var4 = arr;
            int var5 = arr.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String _s = var4[var6];

                try {
                    list.add(Integer.parseInt(_s));
                } catch (Exception var9) {
                }
            }

            return list;
        }
    }

    /**
     * 验证邮箱
     * @param email
     * @return
     */
    public static boolean isEmail(String email) {
        if (isEmpty(email)) {
            return false;
        } else {
            Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
            Matcher m = p.matcher(email);
            return m.matches();
        }
    }

    public static boolean isMobile(String str) {
        return str != null && str.matches("^1[0-9]{10}$");
    }

    public static boolean isBlank(String str) {
        int length;
        if (str != null && (length = str.length()) != 0) {
            for(int i = 0; i < length; ++i) {
                if (!Character.isWhitespace(str.charAt(i))) {
                    return false;
                }
            }

            return true;
        } else {
            return true;
        }
    }

    public static boolean isNotBlank(String str) {
        int length;
        if (str != null && (length = str.length()) != 0) {
            for(int i = 0; i < length; ++i) {
                if (!Character.isWhitespace(str.charAt(i))) {
                    return true;
                }
            }

            return false;
        } else {
            return false;
        }
    }

    public static String exceptionToString(Throwable e) {
        try {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            String errorMsg = sw.toString();
            return errorMsg;
        } catch (Throwable var4) {
            return "";
        }
    }

    public static String tfName2xylName(String tfName) {
        if (isBlank(tfName)) {
            return null;
        } else {
            char[] chars = tfName.toCharArray();

            for(int i = 1; i < chars.length; ++i) {
                char a = chars[i];
                if (a >= 'A' && a <= 'Z') {
                    tfName = tfName.replaceAll("" + a, "_" + ("" + a).toLowerCase());
                }
            }

            String result = tfName.substring(0, 1).toLowerCase() + tfName.substring(1);
            return result;
        }
    }

    public static String xylName2tfName(String xylName) {
        if (isBlank(xylName)) {
            return null;
        } else {
            char[] chars = xylName.toCharArray();

            for(int i = 1; i < chars.length; ++i) {
                char a = chars[i];
                if (a == '_') {
                    xylName = xylName.replaceAll("_" + chars[i + 1], (chars[i + 1] + "").toUpperCase());
                }
            }

            return xylName.replaceAll("_", "");
        }
    }

    public static String urlDecodeUTF8(String str) {
        try {
            return URLDecoder.decode(str, "utf-8");
        } catch (UnsupportedEncodingException var2) {
            return str;
        }
    }

    public static Object stringToObj(String string, Class<?> clz) {
        if (Integer.class.equals(clz)) {
            return Integer.valueOf(string);
        } else if (String.class.equals(clz)) {
            return string;
        } else {
            return Long.class.equals(clz) ? Long.valueOf(string) : null;
        }
    }

    public static List<Long> stringArrToList(String[] strs) {
        if (strs == null) {
            return null;
        } else {
            List<Long> result = new ArrayList();
            String[] var2 = strs;
            int var3 = strs.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                String each = var2[var4];
                result.add(Long.parseLong(each));
            }

            return result;
        }
    }

    public static String listToString(List<Long> list) {
        if (list == null) {
            return null;
        } else {
            StringBuilder buf = new StringBuilder();
            int size = list.size();

            for(int i = 0; i < size; ++i) {
                Long each = (Long)list.get(i);
                buf.append(each);
                if (i != size - 1) {
                    buf.append(",");
                }
            }

            return buf.toString();
        }
    }

    public static Integer[] listToIntegerArr(List<Integer> list) {
        if (list == null) {
            return null;
        } else {
            int size = list.size();
            Integer[] result = (Integer[])list.toArray(new Integer[size]);
            return result;
        }
    }

    public static List<Integer> charToList(char[] cs) {
        if (cs == null) {
            return null;
        } else {
            List<Integer> result = new ArrayList();
            char[] var2 = cs;
            int var3 = cs.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                char c = var2[var4];
                result.add(Integer.valueOf(c));
            }

            return result;
        }
    }

    public static String listToString(List longs, String connChar) {
        if (longs != null && longs.size() != 0) {
            String result = longs.get(0) + "";

            for(int i = 1; i < longs.size(); ++i) {
                result = result + connChar + longs.get(i);
            }

            return result;
        } else {
            return null;
        }
    }

    public static String listToString(List list, String connChar, IListToStringGetVal convert) {
        if (list != null && list.size() != 0) {
            if (convert == null) {
                return null;
            } else {
                String result = convert.getVal(list.get(0)) + "";

                for(int i = 1; i < list.size(); ++i) {
                    result = result + connChar + convert.getVal(list.get(i));
                }

                return result;
            }
        } else {
            return null;
        }
    }

    public static String listToAnswerString(List<Long> list) {
        if (list == null) {
            return null;
        } else {
            StringBuilder buf = new StringBuilder();
            buf.append("[");
            char a = 65;

            for(int i = 0; i < list.size(); ++i) {
                Long each = (Long)list.get(i);
                buf.append((char)(a + each.intValue()));
                if (i == list.size() - 1) {
                    break;
                }

                buf.append(",");
            }

            buf.append("]");
            return buf.toString();
        }
    }

    public static List<Long> stringToList(String str, String split) {
        if (!isBlank(str) && !isBlank(split)) {
            String[] args = str.split(split);
            List<Long> list = new ArrayList();
            if (args != null && args.length > 0) {
                String[] var4 = args;
                int var5 = args.length;

                for(int var6 = 0; var6 < var5; ++var6) {
                    String s = var4[var6];
                    list.add(Long.valueOf(s));
                }
            }

            return list;
        } else {
            return null;
        }
    }

    public static List<String> stringToListStr(String str, String split) {
        if (!isBlank(str) && !isBlank(split)) {
            String[] args = str.split(split);
            List<String> list = new ArrayList();
            if (args != null && args.length > 0) {
                String[] var4 = args;
                int var5 = args.length;

                for(int var6 = 0; var6 < var5; ++var6) {
                    String s = var4[var6];
                    list.add(s);
                }
            }

            return list;
        } else {
            return null;
        }
    }

    public static String firstCharUp(String str) {
        return isBlank(str) ? str : str.substring(0, 1).toUpperCase() + str.substring(1);
    }

    public static String firstCharLower(String str) {
        return isBlank(str) ? str : str.substring(0, 1).toLowerCase() + str.substring(1);
    }

    public static String generateNumStr(Long val, Integer hex, Integer len) throws Exception {
        String hexOctString = BinHexOctUtils.hexOctString(val, hex);
        if (!isEmpty(hexOctString) && len >= hexOctString.length()) {
            StringBuffer sb = new StringBuffer("");

            for(int i = 0; i < len; ++i) {
                sb.append("0");
            }

            sb.append(hexOctString);
            String allStr = sb.toString();
            return allStr.substring(allStr.length() - len);
        } else {
            throw new Exception("len<val hexOctString");
        }
    }

    public static String mockPhone(String phone) throws Exception {
        return isNotBlank(phone) && phone.length() == 11 && phone.startsWith("1") ? phone.substring(0, 8) + "***" : phone;
    }

    public static Integer stringToInteger(Object obj) {
        return obj == null ? null : Integer.valueOf(obj.toString());
    }

    public static Long stringToLong(Object obj) {
        return obj == null ? null : Long.valueOf(obj.toString());
    }

    public static Integer stringToInteger(Object obj, int defaultVal) {
        return obj == null ? defaultVal : Integer.valueOf(obj.toString());
    }

    public static Long stringToLong(Object obj, long defaultVal) {
        return obj == null ? defaultVal : Long.valueOf(obj.toString());
    }

    public static boolean judgeIfSpecial(byte[] c) {
        if (c.length != 2 && c.length != 4) {
            return false;
        } else {
            byte[] b = new byte[2];
            if (c.length == 4) {
                b[0] = c[2];
                b[1] = c[3];
            } else {
                b[0] = c[0];
                b[1] = c[1];
            }

            if (b[0] != -32 && b[0] != -31 && b[0] != -30 && b[0] != -28 && b[0] != -27) {
                return false;
            } else {
                switch(b[0]) {
                    case -32:
                        if (b[1] >= 1 && b[1] <= 90) {
                            return true;
                        }
                        break;
                    case -31:
                        if (b[1] >= 1 && b[1] <= 90) {
                            return true;
                        }
                        break;
                    case -30:
                        if (b[1] >= 1 && b[1] <= 83) {
                            return true;
                        }
                    case -29:
                    default:
                        break;
                    case -28:
                        if (b[1] >= 1 && b[1] <= 76) {
                            return true;
                        }
                        break;
                    case -27:
                        if (b[1] >= 1 && b[1] <= 55) {
                            return true;
                        }
                }

                return false;
            }
        }
    }

    public static String filterEmoji(String name) {
        String realname = name;

        try {
            char[] myBuffer = name.toCharArray();
            StringBuffer sb = new StringBuffer();

            for(int i = 0; i < name.length(); ++i) {
                UnicodeBlock ub = UnicodeBlock.of(myBuffer[i]);
                if (ub == UnicodeBlock.BASIC_LATIN) {
                    sb.append(myBuffer[i]);
                } else if (ub == UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
                    sb.append(myBuffer[i]);
                } else {
                    String temp = String.valueOf(myBuffer[i]);
                    if (!judgeIfSpecial(temp.getBytes("unicode"))) {
                        sb.append(myBuffer[i]);
                    }
                }
            }

            realname = sb.toString();
        } catch (Exception var7) {
            System.out.println(var7);
        }

        return realname;
    }

    public static String indexSubstring(String str, int count) {
        if (!isBlank(str) && count >= 1) {
            return str.length() <= count ? str : str.substring(0, count);
        } else {
            return null;
        }
    }

    public static boolean isLongNum(String str) {
        try {
            Long.valueOf(str);
            return true;
        } catch (Exception var2) {
            return false;
        }
    }

    public static String urlRemoveGetParam(String url) {
        if (!isBlank(url) && url.contains("?")) {
            try {
                int index = url.indexOf("?");
                return url.substring(0, index);
            } catch (Throwable var2) {
                return url;
            }
        } else {
            return url;
        }
    }

    public static String formatFileName(String fileName) {
        if (isBlank(fileName)) {
            fileName = Long.toString(System.nanoTime());
        }

        fileName = fileName.replaceAll("[\\\\\"\\.`~!@#$%^&*()+=|{}':;',\\[\\]<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？《》·]", "");
        if (isBlank(fileName)) {
            fileName = Long.toString(System.nanoTime());
        }

        return fileName;
    }

    public static String formatFileName(String fileName, int maxLen) {
        if (isBlank(fileName)) {
            fileName = Long.toString(System.nanoTime());
        }

        fileName = fileName.replaceAll("[\\\\\"\\.`~!@#$%^&*()+=|{}':;',\\[\\]<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？《》·]", "").replaceAll("\n", "");
        if (isBlank(fileName)) {
            fileName = Long.toString(System.nanoTime());
        }

        return indexSubstring(fileName, maxLen);
    }

    public static String delBlanks(String str) {
        if (isNotBlank(str)) {
            str = str.replaceAll(" ", "");
        }

        return str;
    }

    public static boolean contains(String arrayStr, String arraySplit, String targetStr) {
        if (isBlank(arrayStr)) {
            return false;
        } else if (isBlank(arraySplit)) {
            return false;
        } else if (isBlank(targetStr)) {
            return true;
        } else {
            try {
                String[] arrays = arrayStr.split(arraySplit);
                String[] var4 = arrays;
                int var5 = arrays.length;

                for(int var6 = 0; var6 < var5; ++var6) {
                    String str = var4[var6];
                    if (targetStr.equals(str)) {
                        return true;
                    }
                }
            } catch (Throwable var8) {
            }

            return false;
        }
    }

    public static boolean contains(String[] arrays, String targetStr) {
        if (arrays != null && arrays.length != 0) {
            if (isBlank(targetStr)) {
                return true;
            } else {
                try {
                    String[] var2 = arrays;
                    int var3 = arrays.length;

                    for(int var4 = 0; var4 < var3; ++var4) {
                        String str = var2[var4];
                        if (targetStr.equals(str)) {
                            return true;
                        }
                    }
                } catch (Throwable var6) {
                }

                return false;
            }
        } else {
            return false;
        }
    }

    public static String filterKeyWord(String content, String keywords, String keywordsSplit, String targetWord) {
        if (!isBlank(content) && !isBlank(keywords)) {
            String[] keywordsArray = keywords.split(keywordsSplit);
            return filterKeyWord(content, keywordsArray, targetWord);
        } else {
            return content;
        }
    }

    public static String filterKeyWord(String content, String[] keywords, String targetWord) {
        if (!isBlank(content) && keywords != null) {
            String[] var3 = keywords;
            int var4 = keywords.length;

            for(int var5 = 0; var5 < var4; ++var5) {
                String keyWord = var3[var5];
                content = content.replaceAll(keyWord, targetWord);
            }

            return content;
        } else {
            return content;
        }
    }

    public static boolean containKeyWord(String content, String keywords, String keywordsSplit) {
        if (!isBlank(content) && !isBlank(keywords)) {
            String[] keywordsArray = keywords.split(keywordsSplit);
            return containKeyWord(content, keywordsArray);
        } else {
            return false;
        }
    }

    public static boolean containKeyWord(String content, String[] keywords) {
        if (!isBlank(content) && keywords != null) {
            String[] var2 = keywords;
            int var3 = keywords.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                String keyWord = var2[var4];
                if (content.contains(keyWord)) {
                    return true;
                }
            }

            return false;
        } else {
            return false;
        }
    }

    public static String convertCentToYuan(Long amount) {
        if (amount == null) {
            amount = 0L;
        }

        return String.format("%.2f", Double.valueOf((double)amount) / 100.0D);
    }

    public static String convertCentToYuanWithRmbSymbol(Long amount) {
        return "¥" + convertCentToYuan(amount);
    }

    public static String blurMobile(String mobile) {
        return !isMobile(mobile) ? mobile : mobile.substring(0, 3) + "****" + mobile.substring(7);
    }
}
